#pragma once
#include <GL/gl.h>
#include <glm/glm.hpp>
#include <string>
#include <vector>
#include "shader.h"

class CMesh {

public:
    typedef struct Vertex {
        glm::vec3 position{0.f, 0.f, 0.f};
        glm::vec3 normal{0.f, 0.f, 0.f};
        glm::vec2 texture_coord{0.f, 0.f};
    } SVertex;

    typedef struct Texture {
        GLuint      id{0};
        std::string type;
        std::string path;
    } STexture;

public:
    CMesh(const std::vector<SVertex> vertices, const std::vector<unsigned> &indices)
        : m_vertices(vertices), m_indices(indices)
    {
    }
    CMesh(const std::vector<SVertex> vertices, const std::vector<unsigned> &indices,
          const std::vector<STexture> &texture)
        : m_vertices(vertices), m_indices(indices), m_textures(texture)
    {
    }

    ~CMesh()
    {
        m_vertices.clear();
        m_indices.clear();
        m_textures.clear();
    }

    /**
     * @brief 初始化opengl缓存数组,拷贝网格数据到opengl内存中
     */
    void Init();

    /**
     * @brief 只使用顶点数据绘制模型
     */
    void DrawOnlyUseVertices();

private:
    std::vector<SVertex>  m_vertices;
    std::vector<GLuint>   m_indices;
    std::vector<STexture> m_textures;

private:
    GLuint m_vao = 0;
    GLuint m_ebo = 0;
};